home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Libraries / UMacApp.TDeskScrapView.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  7.2 KB  |  292 lines  |  [TEXT/MPS ]

  1. {$P}
  2. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  3. { UMacApp.TDeskScrapView.p }
  4. { Copyright © 1985-1990 Apple Computer, Inc.  All rights reserved. }
  5.  
  6. {--------------------------------------------------------------------------------------------------}
  7. {$S MAInit}
  8.  
  9. PROCEDURE TDeskScrapView.IDeskScrapView;
  10.  
  11.     VAR
  12.         itsSize:            VPoint;
  13.         aPtr:                PScrapStuff;
  14.  
  15.     BEGIN
  16.     SetVPt(itsSize, 200, 200);
  17.     { Can't know the extent required until we actually read the data in, which we won't bother
  18.         to do unless forced to by receiving an Update event }
  19.  
  20.     IView(NIL, NIL, gZeroVPt, itsSize, sizeVariable, sizeVariable);
  21.  
  22.     aPtr := InfoScrap;
  23.     fScrapCount := aPtr^.scrapCount - 1;
  24.     fDataHandle := NIL;
  25.     fHavePicture := FALSE;
  26.     fHaveText := FALSE;
  27.     END;
  28.  
  29. {--------------------------------------------------------------------------------------------------}
  30. {$S MAInit}
  31.  
  32. PROCEDURE TDeskScrapView.IRes(itsDocument: TDocument;
  33.                               itsSuperView: TView;
  34.                               VAR itsParams: Ptr); OVERRIDE;
  35.  
  36.     VAR
  37.         aPtr:                PScrapStuff;
  38.  
  39.     BEGIN
  40.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  41.  
  42.     aPtr := InfoScrap;
  43.     fScrapCount := aPtr^.scrapCount - 1;
  44.     fDataHandle := NIL;
  45.     fHavePicture := FALSE;
  46.     fHaveText := FALSE;
  47.     END;
  48.  
  49. {--------------------------------------------------------------------------------------------------}
  50. {$S MAClipboard}
  51.  
  52. PROCEDURE TDeskScrapView.Free; OVERRIDE;
  53.  
  54.     BEGIN
  55.     { Never want to free gClipOrphanage.  What if some creates another view of this type? }
  56.     END;
  57.  
  58. {--------------------------------------------------------------------------------------------------}
  59. {$S MAClipboard}
  60.  
  61. PROCEDURE TDeskScrapView.CalcMinSize(VAR minSize: VPoint); OVERRIDE;
  62.  
  63.     VAR
  64.         vhs:                VHSelect;
  65.         aVRect:             VRect;
  66.         aRect:                Rect;
  67.         aTEHandle:            TEHandle;
  68.         oldHText:            Handle;
  69.  
  70.     BEGIN
  71.     minSize := fSize;
  72.     IF fDataHandle <> NIL THEN
  73.         IF fHaveText THEN
  74.             BEGIN                                        { TEXT }
  75.             IF Focus THEN
  76.                 BEGIN
  77.                 SetPortTextStyle(gSystemStyle);
  78.                 fSuperView.GetExtent(aVRect);
  79.                 VRectToRect(aVRect, aRect);
  80.                 aTEHandle := TENew(aRect, aRect);
  81.                 FailNIL(aTEHandle);
  82.  
  83.                 WITH aTEHandle^^ DO
  84.                     BEGIN
  85.                     oldHText := hText;                    { We'll need this for TEDispose }
  86.                     hText := fDataHandle;
  87.                     END;
  88.                 TECalText(aTEHandle);
  89.                 WITH aTEHandle^^ DO
  90.                     BEGIN
  91.                     minSize.h := aRect.right - aRect.left;
  92.                     minSize.v := Min(IntMultiply(nLines, lineHeight), kMaxCoord);
  93.                     hText := oldHText;                    { So TEDispose doesn't dispose our handle }
  94.                     END;
  95.  
  96.                 TEDispose(aTEHandle);
  97.                 END;
  98.             END
  99.  
  100.         ELSE
  101.             BEGIN
  102.             {$IFC qDebug}
  103.             IF gIntenseDebugging THEN
  104.                 BEGIN
  105.                 Write('Picture Frame:');
  106.                 WriteRect(PicHandle(fDataHandle)^^.picFrame);
  107.                 END;
  108.             {$ENDC}
  109.  
  110.             FOR vhs := v TO h DO
  111.                 IF NOT gVarClipPicSize THEN
  112.                     WITH PicHandle(fDataHandle)^^.picFrame DO
  113.                         minSize.vh[vhs] := botRight.vh[vhs] - topLeft.vh[vhs];
  114.             END                                         { PICT } ;
  115.     END;
  116.  
  117. {--------------------------------------------------------------------------------------------------}
  118. {$S MAClipboard}
  119.  
  120. PROCEDURE TDeskScrapView.CheckScrapContents;
  121.  
  122.     VAR
  123.         length:             LONGINT;
  124.         offset:             LONGINT;
  125.         aHandle:            Handle;
  126.         resTypeFound:        ResType;
  127.         savedPerm:            BOOLEAN;
  128.         fi:                 FailInfo;
  129.  
  130.     PROCEDURE HdlFailure(error: OSErr;
  131.                          message: LONGINT);
  132.  
  133.         BEGIN
  134.         aHandle := DisposeIfHandle(aHandle);
  135.         fDataHandle := NIL;
  136.         END;
  137.  
  138.     FUNCTION LookForScrapType(theResType: ResType): BOOLEAN;
  139.  
  140.         VAR
  141.             err:                LONGINT;
  142.             offset:             LONGINT;
  143.  
  144.         BEGIN
  145.         err := GetScrap(NIL, theResType, offset);
  146.         IF err > 0 THEN
  147.             resTypeFound := theResType;
  148.         {$IFC qDebug}
  149.         IF (err <> noTypeErr) & (err < 0) THEN
  150.             WriteLn('LookForScrapType: err = ', err: 1);
  151.         {$ENDC}
  152.         LookForScrapType := err > 0;
  153.         END;
  154.  
  155.     BEGIN
  156.     IF fScrapCount <> gNewScrapStuff.scrapCount THEN
  157.         BEGIN
  158.  
  159.         { Make sure we get rid of the old scrap handle if necessary }
  160.         fDataHandle := DisposeIfHandle(fDataHandle);
  161.  
  162.         fHavePicture := LookForScrapType('PICT');
  163.         fHaveText := LookForScrapType('TEXT');
  164.  
  165.         IF fHavePicture | fHaveText THEN
  166.             BEGIN
  167.             aHandle := NewPermHandle(0);
  168.             FailNIL(aHandle);
  169.  
  170.             CatchFailures(fi, HdlFailure);
  171.             savedPerm := PermAllocation(TRUE);
  172.             length := GetScrap(aHandle, resTypeFound, offset);
  173.             savedPerm := PermAllocation(savedPerm);
  174.  
  175.             IF length < 0 THEN                            { Only results < 0 are really errors }
  176.                 FailOSErr(length);
  177.             fDataHandle := aHandle;
  178.             AdjustSize;
  179.             IF Focus THEN;                                { Make sure we're still focused }
  180.             Success(fi);
  181.             END;
  182.         END;
  183.     END;
  184.  
  185. {--------------------------------------------------------------------------------------------------}
  186. {$S MAClipboard}
  187.  
  188. PROCEDURE TDeskScrapView.Draw(area: Rect);
  189.  
  190.     VAR
  191.         aRect:                Rect;
  192.         vhs:                VHSelect;
  193.  
  194.     BEGIN
  195.     {$IFC qDebug}
  196.     AssumeFocused;
  197.     {$ENDC}
  198.  
  199.     { Has scrap been updated since we last drew? }
  200.     CheckScrapContents;
  201.  
  202.     IF fHaveText THEN
  203.         BEGIN
  204.         SetPortTextStyle(gApplicationStyle);
  205.         GetQDExtent(aRect);
  206.  
  207.         { Does TextEdit handle failure in TextBox??? }
  208.         LockHandleHigh(fDataHandle);                     { Because MATextBox may move memory }
  209.         MATextBox(fDataHandle^, GetHandleSize(fDataHandle), aRect, teJustSystem,
  210.         kAutoWrap, NIL, kNoEraseFirst, kNoSpaceForCaret);
  211.         HUnlock(fDataHandle);
  212.         END
  213.  
  214.     ELSE IF fHavePicture THEN
  215.  
  216.         BEGIN
  217.         IF gVarClipPicSize THEN
  218.             GetQDExtent(aRect)
  219.         ELSE
  220.             BEGIN
  221.             aRect := PicHandle(fDataHandle)^^.picFrame;
  222.             FOR vhs := v TO h DO
  223.                 BEGIN
  224.                 aRect.botRight.vh[vhs] := aRect.botRight.vh[vhs] - aRect.topLeft.vh[vhs];
  225.                 aRect.topLeft.vh[vhs] := 0;
  226.                 END;
  227.             END;
  228.         DrawPicture(PicHandle(fDataHandle), aRect);
  229.         END;
  230.  
  231.     IF fScrapCount <> gNewScrapStuff.scrapCount THEN
  232.         BEGIN
  233.         ValidRect(aRect);                                { avoid flicker upon clipboard installation
  234.                                                          -- but could this cause failure to update
  235.                                                          frame border/appendages sometimes, if that
  236.                                                          code ever checked for visibility before
  237.                                                          drawing ??? }
  238.         fScrapCount := gNewScrapStuff.scrapCount;
  239.         gClipWrittenToDeskScrap := TRUE;                { Don't need to write it back out. }
  240.         END;
  241.  
  242.     INHERITED Draw(area);
  243.     END;
  244.  
  245. {--------------------------------------------------------------------------------------------------}
  246. {$S MAFields}
  247.  
  248. PROCEDURE TDeskScrapView.Fields(PROCEDURE DoToField(fieldName: Str255;
  249.                                                     fieldAddr: Ptr;
  250.                                                     fieldType: INTEGER));
  251.  
  252.     BEGIN
  253.     DoToField('TDeskScrapView', NIL, bClass);
  254.     DoToField('fHavePicture', @fHavePicture, bBoolean);
  255.     DoToField('fHaveText', @fHaveText, bBoolean);
  256.     DoToField('fScrapCount', @fScrapCount, bInteger);
  257.     DoToField('fDataHandle', @fDataHandle, bHandle);
  258.     INHERITED Fields(DoToField);
  259.     END;
  260.  
  261. {--------------------------------------------------------------------------------------------------}
  262. {$S MAInspector}
  263.  
  264. PROCEDURE TDeskScrapView.GetInspectorName(VAR inspectorName: Str255); OVERRIDE;
  265.  
  266.     BEGIN
  267.     IF SELF = gClipView THEN
  268.         inspectorName := 'gClipView'
  269.     ELSE IF SELF = gClipOrphanage THEN
  270.         inspectorName := 'gClipOrphanage';
  271.     END;
  272.  
  273. {--------------------------------------------------------------------------------------------------}
  274. {$S MAClipboard}
  275.  
  276. PROCEDURE TDeskScrapView.SuperViewChangedSize(delta: VPoint;
  277.                                               invalidate: BOOLEAN); OVERRIDE;
  278.  
  279.     BEGIN
  280.     AdjustSize;
  281.     ForceRedraw;
  282.     END;
  283.  
  284. {--------------------------------------------------------------------------------------------------}
  285. {$S MAClipboard}
  286.  
  287. PROCEDURE TDeskScrapView.WriteToDeskScrap; OVERRIDE;
  288.  
  289.     BEGIN
  290.     { This view represents data that's already written to the desk scrap }
  291.     END;
  292.